package com.richman.isn;

import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.json.JSONObject;

import com.richman.controller.DecreaseRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.Event;

public class ISNManager {

	
	
	ISNHttp account = null;

	public void init() {
		
		Vector<String[]> tmps = DecreaseRatioClient.mainWnd.getISNAccounts();
		if(tmps.size() > 0) {
			
			ISNHttp isnhttp = new ISNHttp();
			isnhttp.setLoginParams(tmps.elementAt(0)[0], tmps.elementAt(0)[1],
					tmps.elementAt(0)[2]);
			
			account = isnhttp;
			
		}
		

	}
	
	public void login() {
		
		if(account != null) {
			
			if(account.getStatusCode() == -1 && System.currentTimeMillis() > account.getCanLoginTime()) {
				account.login();
			}
		}

	}

	public void checkIsOnline() {
		try {
			
			if(account != null) {
				
				if(account.getStatusCode() == 1 || account.getStatusCode() == 2) {
					account.getbalance();
				}
			}
			
		}catch(Exception e) {
			e.printStackTrace();
		}
	}



	public int getStatuscode() {
		if(account != null) {
			return account.getStatusCode();
			
		}
		return 0;
	}
	
	
	public void updateStatuscode(int i) {
		if(account != null) {
			account.updateStatusCode(i);
			
		}
	}
	
	public String getOutlineData() {
		if(account != null) {
			return account.getOutlineData();		
		}		
		return null;
	}
	
//	
//	public Map<String, String> updatePS38Ratio(String betid, String eventid, String bettype, String typedetail, String pankou) {
//		
//		try {
//			
//			if(account != null) {
//				return account.updatePS38Ratio(betid, eventid, bettype, typedetail, pankou);
//				
//			}
//			
//		}catch(Exception e) {
//			e.printStackTrace();
//		}
//		
//		return null;
//		
//	}



	public void getbalance() {
		if(account != null && account.getStatusCode() == 1 && System.currentTimeMillis() > account.getCanGetBalanceTime() ) {
			account.getbalance();
			
		}
		
	}



	public Map<String,String> dobet(String homeTeam, String awayTeam, String updown, String bettype, int gold, Double pankouarg,double ratio) {
		if(account != null) {
			return account.dobet(homeTeam, awayTeam, updown, bettype, gold, pankouarg,0.0,0);
		}
		return null;
	}
	
	public String dobetdxq(String homeTeam, String awayTeam, String updown, double ratio, int gold, Vector<Double> hgpankous) {
		if(account != null) {
			return account.dobetdxq(homeTeam, awayTeam, updown, ratio, gold, hgpankous);
		}
		return null;
	}

	public void updatehgSpecialAccountBetLogData(Vector<BetAdyData> specialBetLogDatas) {
		if(account != null) {
			account.updatehgBetLogData(specialBetLogDatas);
		}
		
	}

	public String getDetailsData(String datetime) {
		if(account != null) {
			return account.getDetailsData(datetime);		
		}		
		return null;
	}

	public JSONObject getISNEvent() {
		if(account != null) {
			return account.getISNEvents();
		}
		return null;
	}

	public String getISNbetAccount() {
		if(account != null) {
			return account.getAccount();
		}
		return null;
	}

	public Map<String, String> updateISNRatio(String homeTeam, String awayTeam, String updown, String bettype,
			Double pankouarg) {
		if(account != null) {
			return account.updateISNRatio(homeTeam,  awayTeam,  updown,  bettype,   pankouarg);
		}
		return null;
	}



//	public void updateps38BetLogData(Vector<BetAdyData> betLogDatas) {
//		if(account != null && account.getStatusCode() == 2) {
//			account.updateps38BetLogData(betLogDatas);
//		}
//	} 
	

	
}
